{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check If It Is a Good Array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Hard"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array #math #number-theory"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组 #数学 #数论"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isGoodArray"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #检查「好数组」"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个正整数数组 <code>nums</code>，你需要从中任选一些子集，然后将子集中每一个数乘以一个 <strong>任意整数</strong>，并求出他们的和。</p>\n",
    "\n",
    "<p>假如该和结果为&nbsp;<code>1</code>，那么原数组就是一个「<strong>好数组</strong>」，则返回 <code>True</code>；否则请返回 <code>False</code>。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [12,5,7,23]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>挑选数字 5 和 7。\n",
    "5*3 + 7*(-2) = 1\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [29,6,10]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>挑选数字 29, 6 和 10。\n",
    "29*1 + 6*(-3) + 10*(-1) = 1\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>nums = [3,6]\n",
    "<strong>输出：</strong>false\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= nums.length &lt;= 10^5</code></li>\n",
    "\t<li><code>1 &lt;= nums[i] &lt;= 10^9</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-if-it-is-a-good-array](https://leetcode.cn/problems/check-if-it-is-a-good-array/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-if-it-is-a-good-array](https://leetcode.cn/problems/check-if-it-is-a-good-array/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[12,5,7,23]', '[29,6,10]', '[3,6]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        for i in range(1,len(nums)):nums[i]=math.gcd(nums[i-1],nums[i])\n",
    "        return nums[-1]==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        def gcd(a, b):\n",
    "            while b:\n",
    "                a, b = b, a % b\n",
    "            return a\n",
    "        n=len(nums)\n",
    "        if n==1 and nums[0]==1:\n",
    "            return True\n",
    "        for i in range(n-1):\n",
    "            nums[i+1]=gcd(nums[i],nums[i+1])\n",
    "            if nums[i+1]==1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(math.gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        g = nums[0]\n",
    "        for i in range(1,len(nums)):\n",
    "            g = gcd(g,nums[i])\n",
    "        if g > 1:\n",
    "            return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd,nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        g = nums[0]\n",
    "        for x in nums:\n",
    "            g = gcd(x, g)\n",
    "            if g == 1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        # 计算数组中所有元素的最大公约数\n",
    "        gcd = nums[0]\n",
    "        for num in nums:\n",
    "            gcd = math.gcd(gcd, num)\n",
    "        \n",
    "        # 如果最大公约数为1，返回True，否则返回False\n",
    "        return gcd == 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd,nums)==1\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def gcd(self,a:int,b:int)->int:\n",
    "        if b == 0:\n",
    "            return a\n",
    "        else:\n",
    "            return gcd(b,a %b )\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        res = nums[0]\n",
    "        for i in range(1,len(nums)):\n",
    "            res = self.gcd(res,nums[i])\n",
    "\n",
    "        return res==1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd,nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd,nums)==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        res = 0\n",
    "        for num in nums:\n",
    "            res = math.gcd(res, num)\n",
    "        return res==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from typing import List\n",
    "from math import gcd\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        # 初始化 GCD 为数组的第一个元素\n",
    "        current_gcd = nums[0]\n",
    "        \n",
    "        # 通过迭代来找出数组中所有数的 GCD\n",
    "        for num in nums:\n",
    "            current_gcd = gcd(current_gcd, num)\n",
    "            \n",
    "            # 如果在任何时刻 GCD 是 1，我们可以提前退出循环\n",
    "            if current_gcd == 1:\n",
    "                return True\n",
    "        \n",
    "        return current_gcd == 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        \n",
    "        def gcd(a, b):\n",
    "            return a if b == 0 else gcd(b, a % b)\n",
    "        \n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return functools.reduce(math.gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "\n",
    "        def my_gcd(a, b):\n",
    "            if not b:\n",
    "                return a\n",
    "            return my_gcd(b, a % b)\n",
    "\n",
    "        pre = nums[0]\n",
    "        for x in nums:\n",
    "            cur = my_gcd(x, pre)\n",
    "            if cur == 1:\n",
    "                return True\n",
    "            pre = cur\n",
    "        return False "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd,nums)==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return gcd(*nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        pre = nums[0]\n",
    "        for x in nums:\n",
    "            cur = gcd(x, pre)\n",
    "            if cur == 1:\n",
    "                return True\n",
    "            pre = cur\n",
    "        return False "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        def mygcd(a,b):\n",
    "            if b==0:\n",
    "                return a\n",
    "            else:\n",
    "                return mygcd(b,a % b)\n",
    "        return reduce(mygcd,nums)==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        divisor = nums[0]\n",
    "        for num in nums:\n",
    "            divisor = gcd(num, divisor)\n",
    "            if divisor == 1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        if nums[0] == 1:\n",
    "            return True\n",
    "        x = nums[0]\n",
    "        for i in range(1, len(nums)):\n",
    "            #print(x, nums[i])\n",
    "            x = self.gcd(x, nums[i])\n",
    "            #print(x)\n",
    "            if x == 1:\n",
    "                return True\n",
    "        return False\n",
    "    \n",
    "    def gcd(self, x, y):\n",
    "        if x < y:\n",
    "            x, y = y, x\n",
    "        z = x % y\n",
    "        while z != 0:\n",
    "            x = z\n",
    "            if x < y:\n",
    "                x, y = y, x\n",
    "            z = x % y\n",
    "        return y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd,nums) == 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return math.gcd(*nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd, nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        m = nums[0]\n",
    "        s = set([])\n",
    "        i = 2\n",
    "        while i <= m:\n",
    "            if m % i == 0:\n",
    "                s.add(i)\n",
    "                m = m // i\n",
    "            else:\n",
    "                i += 1\n",
    "        # print(s)\n",
    "        for num in nums:\n",
    "            for e in s:\n",
    "                if num % e != 0:\n",
    "                    s = s - {e}\n",
    "            if not s:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd,nums)==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return reduce(gcd,nums)==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return math.gcd(*nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return math.gcd(*nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return gcd(*nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        def gcd(a, b):\n",
    "            return b if not a % b else gcd(b, a%b)\n",
    "        \n",
    "        GCD = nums[0]\n",
    "        for num in nums[1:]:\n",
    "            GCD = gcd(GCD, num)\n",
    "        \n",
    "        return True if GCD == 1 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return gcd(*nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return gcd(*nums) == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        if len(nums) == 1:\n",
    "            return nums[0] == 1\n",
    "        res = gcd(nums[0], nums[1])\n",
    "        for e in nums[2:]:\n",
    "            res = gcd(res, e)\n",
    "            if res == 1:\n",
    "                return True\n",
    "        return res == 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        return gcd(*nums) == 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        n = len(nums)\n",
    "        res = nums[0]\n",
    "        for i in range(1,n):\n",
    "            res = gcd(nums[i],res)\n",
    "        return res == 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums: List[int]) -> bool:\n",
    "        ans=nums[0]\n",
    "        for num in nums[1:]:\n",
    "            ans=gcd(num,ans)\n",
    "            if ans==1:\n",
    "                return True\n",
    "        return ans==1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isGoodArray(self, nums) -> bool:\n",
    "        def gdc(a, b):\n",
    "            if a % b == 0:\n",
    "                return b\n",
    "            else:\n",
    "                return gdc(b, a % b)\n",
    "        \n",
    "        n = nums[0]\n",
    "        for m in nums[1:]:\n",
    "            n = gdc(n, m)\n",
    "        \n",
    "        return n == 1"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
